#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std; 

#define MAX_N	201
#define INF		100000
int p, k, s; 
char a[MAX_N]; 
int alen; 

struct word_s {
	char w[MAX_N]; 
	int len; 
}; 

struct word_s word[10]; 
int w[MAX_N][MAX_N]; 
int F[MAX_N][MAX_N]; 

bool cmp(word_s &a, word_s &b)
{
	return a.len<b.len; 
}

int main()
{
	int i, j, r; 
	int x, y; 

	freopen("p1026_03.in", "r", stdin); 
	scanf("%d %d\n", &p, &k); 
	for(i=0; i<p; i++) {
		scanf("%s\n", a+20*i+1); 
		*(a+20*i+20+1)='\0'; 
	}
	alen = p*20; 
	scanf("%d\n", &s); 
	for (i=0; i<s; i++) {
		scanf("%s", word[i].w); 
		word[i].len = strlen(word[i].w);
	}
	sort(word, word+s, cmp); 
	/*
	for (i=0; i<s; i++) {
		printf("%d: %s\n", i, word[i].w); 
	}*/

	for (i=1; i<=alen; i++) {
		for (j=0; j<s; j++) {
			if (strncmp(a+i, word[j].w, word[j].len)!=0) {
				continue;
			}
			//printf("--> %d: %s\n", i, word[j].w); 
			for (x=1; x<=i; x++) {
				for (y=i+word[j].len-1; y<=alen; y++) {
					w[x][y] ++; 
				}
			}
			break; 
		}
	}
	/*
	for (i=1; i<=alen; i++) {
		for (j=i; j<=alen; j++) {
			printf("w[%d][%d] = %d\n", i, j, w[i][j]); 
		}
	} */
	
	for (i=1; i<=alen; i++) {
		F[i][1] = w[1][i]; 
		//printf("F[%d][1] = %d\n", i, F[i][1]); 
	}
	// F[i][j] = max(F[r][j-1]+w[r+1][i]) , r=j...i-1
	for (i=1; i<=alen; i++) {
		for(j=1; j<=k; j++) {
			F[i][j] = max(0, F[i][j]); 
			//printf("  j=%d\n", j); 
			for (r=j; r<=i-1; r++) {
				//printf("     r=%d\n", r); 
				F[i][j] = max(F[i][j], F[r][j-1]+w[r+1][i]); 
			}
			//printf("F[%d][%d] = %d\n", i, j, F[i][j]); 
		}
	}	
	
	printf("%d\n", F[alen][k]); 
	return 0; 
}


